/*
 * @lc app=leetcode.cn id=228 lang=javascript
 *
 * [228] 汇总区间
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {string[]}
 */
var summaryRanges = function (nums) {
  if (nums.length === 0) return [];
  let start = nums[0];
  let result = [];
  for (let i = 1; i < nums.length; i++) {
    if (nums[i] !== nums[i - 1] + 1) {
      result.push(start === nums[i - 1] ? `${start}` : `${start}->${nums[i - 1]}`)
      start = nums[i];
    }
  }
  result.push(start === nums[nums.length - 1] ? `${start}` : `${start}->${nums[nums.length - 1]}`)
  return result;
};
// @lc code=end

